﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XiaoGang.Soft.XGWMS.BLL;
using XiaoGang.Soft.XGWMS.COM;

namespace XiaoGang.Soft.XGWMS.UI
{
    public partial class M007GoodsEdit : FormBase
    {
        #region 变量定义

        private bool blFormLoad = false;
        private readonly BLL.BLL_M007_GOODS bll_M007_GOODS;
        private bool blnFlag = false;//入库业务调用的标志位
        private string FatherForm = "";
        private readonly MODEL.MOD_M007_GOODS SearchModel;

        /// <summary>
        /// 商品实体
        /// </summary>
        private readonly MODEL.MOD_M007_GOODS entityGoods;
        private int intFirstDisplayedScrollingRowIndex = 0;
        private bool AddRowFlag = true;
        private bool SearchFlag = false;

        /// <summary>
        /// 商品
        /// </summary>
        private const string dataName = "商品";

        #endregion

        #region 方法

        /// <summary>
        /// 构造函数
        /// </summary>
        public M007GoodsEdit()
        {
            InitializeComponent();
            entityGoods = new MODEL.MOD_M007_GOODS();
            bll_M007_GOODS = new BLL_M007_GOODS();
            SearchModel = new MODEL.MOD_M007_GOODS();
            InitProcess();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="bln"></param>
        public M007GoodsEdit(MODEL.MOD_M007_GOODS entityEdit)
        {
            InitializeComponent();
            entityGoods = entityEdit;
            bll_M007_GOODS = new BLL_M007_GOODS();
            SearchModel = new MODEL.MOD_M007_GOODS();
            InitProcess();
        }

        /// <summary>
        /// <p><b>方法名称</b>SetTabIndex</p>	
        /// <p><b>概要説明	:</b>画面フォーカスの遷移順の設定</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// </summary>	
        protected void SetTabIndex()
        {
            int intIndex = 0;
            txtGOODS_NM1.TabIndex = intIndex; intIndex++;
            txtGOODS_NM2.TabIndex = intIndex; intIndex++;
            txtPROVIDER.TabIndex = intIndex; intIndex++;
            txtMEMO.TabIndex = intIndex; intIndex++;
            cmbGOODS_GROUP.TabIndex = intIndex; intIndex++;
            btnGOODS_GROUP.TabIndex = intIndex; intIndex++;
            txtMAX_WARN.TabIndex = intIndex; intIndex++;
            txtMIN_WARN.TabIndex = intIndex; intIndex++;
            txtMoney.TabIndex = intIndex; intIndex++;//销售单价
            txtDiscount.TabIndex = intIndex; intIndex++;//打折
            grpInPut.TabIndex = intIndex; intIndex++;//
            txtUNITS.TabIndex = intIndex; intIndex++;//入库数量
            txtBUYING_PRICE.TabIndex = intIndex; intIndex++;//进价
            cmbSTOREROOM_ID.TabIndex = intIndex; intIndex++;//仓库
            btnClear.TabIndex = intIndex; intIndex++;
            btnAdd.TabIndex = intIndex; intIndex++;
            btnExit.TabIndex = intIndex; intIndex++;
            txtGOODS_ID.TabIndex = intIndex; intIndex++;
            txtGOODS_NO.TabIndex = intIndex; intIndex++;
        }

        /// <summary>
        /// <p><b>方法名称</b>ClearControl</p>	
        /// <p><b>概要説明	:</b>画面上の全項目をオールクリアする</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// </summary>	
        protected void ClearControl()
        {
            txtGOODS_ID.Text = entityGoods.GOODS_ID;
            txtGOODS_NO.Text = entityGoods.GOODS_NO;
            txtGOODS_NM1.Text = entityGoods.GOODS_NM1;
            txtGOODS_NM2.Text = entityGoods.GOODS_NM2;
            txtPROVIDER.Text = entityGoods.PROVIDER;
            txtMEMO.Text = entityGoods.MEMO;
            txtMAX_WARN.Text = entityGoods.MAX_WARN.ToString();
            txtMIN_WARN.Text = entityGoods.MIN_WARN.ToString();
            txtMoney.Text = entityGoods.SalePrice.ToString();
            txtDiscount.Text = (entityGoods.Discount*10).ToString();
            cmbGOODS_GROUP.SelectedValue = entityGoods.GOODS_GROUP;
            txtUNITS.Text = "";//数量
            txtBUYING_PRICE.Text = "";//进价
            cmbSTOREROOM_ID.SelectedIndex = 0;//仓库
        }

        /// <summary>
        /// <p><b>方法名称</b>SetEnable</p>
        /// <p><b>概要説明  :</b>画面モードのセト</p>
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>
        protected void SetEnable()
        {
            grpGoodsInfo.Enabled = true;
            txtGOODS_ID.Enabled = false;
            txtGOODS_NO.Enabled = true;
            txtGOODS_NM1.Enabled = true;
            txtGOODS_NM2.Enabled = true;
            txtPROVIDER.Enabled = true;
            txtMEMO.Enabled = true;
            cmbGOODS_GROUP.Enabled = true;
            txtMAX_WARN.Enabled = true;
            txtMIN_WARN.Enabled = true;
            txtMoney.Enabled = true;//销售单价
            txtUNITS.Enabled = true;//数量
            txtBUYING_PRICE.Enabled = true;//进价
            cmbSTOREROOM_ID.Enabled = true;//仓库
            txtDiscount.Enabled = true;//打折
            btnAdd.Enabled = true;
            btnExit.Enabled = true;
        }

        /// <summary>
        /// <p><b>方法名称</b>InitComBox</p>
        /// <p><b>概要説明  :</b>ComBoxの初期化する</p>
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>
        protected void InitComBox()
        {
            Method.CmbDataBound("GOODS_GROUP_ID", cmbGOODS_GROUP);
            cmbGOODS_GROUP.SelectedIndex = 0;
            Method.CmbDataBound("STOREROOM_ID", cmbSTOREROOM_ID);
            cmbSTOREROOM_ID.SelectedIndex = 0;
        }        

        /// <summary>	
        /// <p><b>方法名称</b>InitProcess</p>	
        /// <p><b>概要説明	:</b>窗口初始化</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// </summary>
        protected void InitProcess()
        {
            SetTabIndex();
            SetEnable();
            InitComBox();
            ClearControl();
        }
        
        /// <summary>
        /// <p><b>方法名称</b>CheckProcess</p>	
        /// <p><b>概要説明  :</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>	
        /// <param name="strConstrolName">控件名称</param>
        /// <returns></returns>
        protected override bool CheckProcess(string strConstrolName)
        {
            string strValue = string.Empty;
            try
            {
                switch (strConstrolName)
                {
                    case "txtGOODS_ID":
                        strValue = this.txtGOODS_ID.Text.Trim();
                        if (!Method.CheckIsNumber(strValue, txtGOODS_ID.MaxLength, false,true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtGOODS_ID.Focus();                         
                            return false;
                        }
                        break;
                    case "txtGOODS_NO":
                        strValue = this.txtGOODS_NO.Text.Trim();
                        if (!Method.CheckIsNumber(strValue, txtGOODS_NO.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtGOODS_NO.Focus();                         
                            return false;
                        }
                        break;
                    case "txtGOODS_NM1":
                        strValue = this.txtGOODS_NM1.Text.Trim();
                        if (0 == txtGOODS_NM1.Text.Trim().Length)
                        {
                            Method.MessageShow("W11E02", "商品名称");//[@]不能为空！
                            txtGOODS_NM1.Focus();                         
                            return false;
                        }
                        if (Encoding.Default.GetByteCount(strValue) > txtGOODS_NM1.MaxLength)
                        {
                            Method.MessageShow("W11007",dataName);
                            txtGOODS_NM1.Focus();
                            return false;
                        }
                        if (Method.CheckIsIncludeSpecailChar(Method.ToDBC(txtGOODS_NM1.Text)) == false)
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtGOODS_NM1.Focus();
                            return false;
                        }
                        break;
                    case "txtGOODS_NM2":
                        strValue = this.txtGOODS_NM2.Text.Trim();
                        if (Encoding.Default.GetByteCount(strValue) > txtGOODS_NM2.MaxLength)
                        {
                            Method.MessageShow("W11007",dataName);
                            txtGOODS_NM2.Focus();
                            return false;
                        }
                        if (Method.CheckIsIncludeSpecailChar(Method.ToDBC(txtGOODS_NM2.Text)) == false)
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtGOODS_NM2.Focus();
                            return false;
                        }
                        break;
                    case "txtPROVIDER":
                        strValue = this.txtPROVIDER.Text.Trim();
                        if (Encoding.Default.GetByteCount(strValue) > txtPROVIDER.MaxLength)
                        {
                            Method.MessageShow("W11007", dataName);
                            txtPROVIDER.Focus();
                            return false;
                        }
                        if (Method.CheckIsIncludeSpecailChar(Method.ToDBC(strValue)) == false)
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtPROVIDER.Focus();
                            return false;
                        }
                        break;
                    case "txtMEMO":
                        strValue = this.txtMEMO.Text.Trim();
                        if (Encoding.Default.GetByteCount(strValue) > txtMEMO.MaxLength)
                        {
                            Method.MessageShow("W11007", dataName);
                            txtMEMO.Focus();
                            return false;
                        }
                        if (Method.CheckIsIncludeSpecailChar(Method.ToDBC(strValue)) == false)
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtMEMO.Focus();
                            return false;
                        }
                        break;
                    case "cmbGOODS_GROUP":
                        if (cmbGOODS_GROUP.SelectedIndex == 0)
                        {
                            Method.MessageShow("W11015", dataName);
                            cmbGOODS_GROUP.Focus();
                            cmbGOODS_GROUP.SelectAll();
                            return false;
                        }
                        break;
                    case "txtMAX_WARN":
                        strValue = this.txtMAX_WARN.Text.Trim().Replace(",", "");
                        if (!Method.CheckIsNumber(strValue, txtMAX_WARN.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtMAX_WARN.Focus();
                            return false;
                        }
                        break;
                    case "txtMIN_WARN":
                        strValue = this.txtMIN_WARN.Text.Trim().Replace(",", "");
                        if (!Method.CheckIsNumber(strValue, txtMIN_WARN.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtMIN_WARN.Focus();
                            return false;
                        }                        
                        break;
                    case "txtMoney":
                        strValue = this.txtMoney.Text.Trim().Replace(",", "");
                        if (!Method.CheckIsNumerc(strValue, txtMoney.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtMoney.Focus();
                            return false;
                        }
                        break;
                    case "txtDiscount"://折扣
                        strValue = this.txtDiscount.Text.Trim();
                        if (!Method.CheckIsNumerc(strValue, txtDiscount.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtDiscount.Focus();
                            return false;
                        }
                        if (strValue.Length > 0)
                        {
                            if (double.Parse(strValue) > 10 || double.Parse(strValue) <= 0)
                            {
                                Method.MessageShow("W11038", dataName);//折扣只能是介于0到10的数字！
                                txtDiscount.Focus();
                                return false;
                            }
                        }
                        break;
                    case "txtUNITS"://入库数量
                        strValue = this.txtUNITS.Text.Trim().Replace(",", "");
                        if (!Method.CheckIsNumber(strValue, txtUNITS.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtUNITS.Focus();
                            return false;
                        }
                        break;
                    case "txtBUYING_PRICE"://进价
                        strValue = this.txtBUYING_PRICE.Text.Trim().Replace(",", "");
                        if (!Method.CheckIsNumerc(strValue, txtBUYING_PRICE.MaxLength, true, true))
                        {
                            Method.MessageShow(GlobalVal.glostrMsg,dataName);
                            txtBUYING_PRICE.Focus();
                            return false;
                        }
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteClientErrLog4Net(ex);
                return false;
            }
            return true;
        }

        /// <summary>
        /// <p><b>方法名：</b>CheckProcessLoop</p>	
        /// <p><b>概要説明:</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>	
        /// <param name="operation">Check状态枚举</param>
        /// <returns></returns>
        protected bool CheckProcessLoop(enumOperation emOperation)
        {
            switch (emOperation)
            {
                case enumOperation.Add:
                    if (!CheckProcess("txtGOODS_NO")) return false;
                    if (!CheckProcess("txtGOODS_NM1")) return false;
                    if (!CheckNameAdd()) return false;
                    if (!CheckProcess("txtGOODS_NM2")) return false;
                    if (!CheckProcess("txtPROVIDER")) return false;
                    if (!CheckProcess("txtMEMO")) return false;
                    if (!CheckProcess("cmbGOODS_GROUP")) return false;
                    if (!CheckProcess("txtMAX_WARN")) return false;
                    if (!CheckProcess("txtMIN_WARN")) return false;
                    if (!CheckProcess("txtMoney")) return false;//销售单价
                    if (!CheckProcess("txtDiscount")) return false;//打折
                    if (!CheckProcess("txtUNITS")) return false;//入库数量
                    if (!CheckProcess("txtBUYING_PRICE")) return false;//进价
                    break;
                case enumOperation.Update:
                    if (CheckProcess("txtGOODS_ID") == false) return false;
                    if (!CheckProcess("txtGOODS_NO")) return false;
                    if (!CheckProcess("txtGOODS_NM1")) return false;
                    if (!CheckNameUpdate()) return false;
                    if (!CheckProcess("txtGOODS_NM2")) return false;
                    if (!CheckProcess("txtPROVIDER")) return false;
                    if (!CheckProcess("txtMEMO")) return false;
                    if (!CheckProcess("cmbGOODS_GROUP")) return false;
                    if (!CheckProcess("txtMAX_WARN")) return false;
                    if (!CheckProcess("txtMIN_WARN")) return false;
                    if (!CheckProcess("txtMoney")) return false;
                    if (!CheckProcess("txtDiscount")) return false;
                    break;
                case enumOperation.Search:
                    break;
                case enumOperation.Delete:
                    if (CheckProcess("txtGOODS_ID") == false) return false;
                    //if (GoodsDeleteCheck(txtGOODS_ID.Text.Trim()) == false)
                    //{
                    //    return false;
                    //}
                    break;
                default:
                    break;
            }
            return true;
        }

        /// <summary>	
        /// <p><b>方法名称</b>DateFormat</p>	
        /// <p><b>概要説明  :</b>date data format</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param name="strValue">没有格式化的字符串</param> 
        /// <returns type="string">格式化后的字符串</returns>
        protected string DateFormat( string strValue )
        {
            if (strValue.Length < 8)
            {
                return strValue;
            }
            return strValue.Substring(0, 4) + "/" +
                strValue.Substring(4, 2) + "/" +
                strValue.Substring(6, 2);
        }     

        /// <summary>	
        /// <p><b>方法名称</b>NumPriceFormat</p>	
        /// <p><b>概要説明  :</b>num and price data format</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/08/27</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>
        /// <param name="strValue">没有格式化的字符串</param> 
        /// <returns type="string">格式化后的字符串</returns>
        protected string NumPriceFormat(string strValue)
        {
            string strTemp = strValue;            
            if (strValue.Length > 6)
            {
                strTemp = strValue.Substring(0, strValue.Length - 6) + ","
                    + strValue.Substring((strValue.Substring(0, strValue.Length - 6)).Length, 3)
                    + "," + strValue.Substring(strValue.Length - 3, 3);

            }
            else if (strValue.Length > 3)
            {
                strTemp = strValue.Substring(0, strValue.Length - 3) + ","
                + strValue.Substring((strValue.Substring(0, strValue.Length - 3)).Length, 3);
            }
            return strTemp;
        }                

        /// <summary>
        /// <p><b>方法名称</b>GoodsDeleteCheck</p>	
        /// <p><b>概要説明  :</b>检测该商品有没有没使用</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/16</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" name="strGoodsID">商品编码</param>
        /// <returns type = "ReturnValue">商品编码</returns>
        public bool GoodsDeleteCheck(string strGoodsID)
        {
            ReturnValue rvReturnValue =
                bll_M007_GOODS.GoodsDeleteCheck(strGoodsID);

            if (rvReturnValue.IsSuccess == false)
            {
                Method.MessageShow(rvReturnValue.ErrorID,dataName);
                return false;
            }
            if (rvReturnValue.ResultDataSet.Tables[0].Rows.Count != 0)
            {
                Method.MessageShow("W11029", dataName);
                txtGOODS_ID.Focus();
                txtGOODS_ID.SelectAll();
                return false;
            }
            return true;
        }

        /// <summary>
        /// <p><b>方法名称</b>CheckName</p>
        /// <p><b>概要説明  :</b>添加时商品名的Check</p>
        /// <p><b>作成者    :</b>万岗</p>
        /// <p><b>作成日    :</b>2008/09/17</p>
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <returns type = "bool">false:存在 true:不存在</returns>
        public bool CheckNameAdd()
        {
            MODEL.MOD_M007_GOODS model = new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS();
            model.GOODS_NM1 = txtGOODS_NM1.Text.Trim();
            ReturnValue rvReturnValue = bll_M007_GOODS.CheckName(model);
            if (rvReturnValue.IsSuccess == false)
            {
                Method.MessageShow(rvReturnValue.ErrorID,dataName);                
                return false;
            }
            if (0 != rvReturnValue.ResultDataSet.Tables[0].Rows.Count)
            {
                Method.MessageShow("W11E01", dataName);//本[@]已经存在。
                txtGOODS_NM1.Focus();
                return false;               
            }
            return true;
        }

        /// <summary>
        /// <p><b>方法名称</b>CheckName</p>	
        /// <p><b>概要説明  :</b>更新时商品名的Check</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/17</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <returns type = "bool">false:存在 true:不存在</returns>
        public bool CheckNameUpdate()
        {
            MODEL.MOD_M007_GOODS model =
                new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS();
            model.GOODS_NM1 = txtGOODS_NM1.Text.Trim();
            model.GOODS_ID = txtGOODS_ID.Text.Trim();

            ReturnValue rvReturnValue = bll_M007_GOODS.CheckName(model);
            if (rvReturnValue.IsSuccess == false)
            {
                Method.MessageShow(rvReturnValue.ErrorID,dataName);
                return false;
            }
            if ((0 != rvReturnValue.ResultDataSet.Tables[0].Rows.Count) && model.GOODS_ID.Trim() != rvReturnValue.ResultDataSet.Tables[0].Rows[0]["GOODS_ID"].ToString().Trim())
            {
                Method.MessageShow("W11E01", dataName);//本[@]已经存在。
                txtGOODS_NM1.Focus();
                return false;
            }
            return true;
        }
        #endregion

        #region 事件

        private void M007_GOODS_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F5:
                    AllButton_Click(btnAdd, e);
                    break;
                case Keys.F12:
                    AllButton_Click(btnClear, e);
                    break;
                case Keys.Escape:
                    AllButton_Click(btnExit, e);
                    break;
            }          
        }

        private void GoodsForm_Load(object sender, EventArgs e)
        {

        }
        
        private void AllButton_Click(object sender, EventArgs e)
        {
            if (this.Cursor == Cursors.WaitCursor)
            {
                return;
            }
            switch (((Button)sender).Name)
            {
                #region btnAdd
                case "btnAdd":                    
                    //验证数据合法性
                    if (txtGOODS_ID.Text.Trim().Length < 1 && !this.CheckProcessLoop(enumOperation.Add))
                    {
                        return;
                    }
                    if (txtGOODS_ID.Text.Trim().Length > 0 && !this.CheckProcessLoop(enumOperation.Update))
                    {
                        return;
                    }
                    this.Cursor = Cursors.WaitCursor;
                    entityGoods.Clear();
                    entityGoods.UPDATER_ID = GlobalVal.gloUserInfo.USER_ID;       /*更新者*/
                    entityGoods.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD;  /*终端*/
                    entityGoods.GOODS_ID = txtGOODS_ID.Text.Trim();               /*商品编码*/
                    entityGoods.GOODS_NO = txtGOODS_NO.Text.Trim();               /*商品条码*/
                    entityGoods.GOODS_NM1 = txtGOODS_NM1.Text.Trim();             /*商品名称1*/
                    entityGoods.GOODS_NM2 = txtGOODS_NM2.Text.Trim();             /*商品名称2*/
                    if (cmbGOODS_GROUP.SelectedIndex != -1)                 /*商品分类*/
                    {
                        entityGoods.GOODS_GROUP = cmbGOODS_GROUP.SelectedValue.ToString().Trim();
                    }
                    entityGoods.PROVIDER = txtPROVIDER.Text.Trim();               /*提供商*/
                    if (txtMAX_WARN.Text.Trim().Length > 0)                 /*最大库存*/
                    {
                        entityGoods.MAX_WARN = int.Parse(txtMAX_WARN.Text.Trim().Replace(",", ""));
                    }
                    if (txtMIN_WARN.Text.Trim().Length > 0)                 /*最小库存*/
                    {
                        entityGoods.MIN_WARN = int.Parse(txtMIN_WARN.Text.Trim().Replace(",", ""));
                    }
                    if (txtMoney.Text.Trim().Length > 0)                    /*售价*/
                    {
                        entityGoods.SalePrice = decimal.Parse(txtMoney.Text.Trim().Replace(",", ""));
                    }
                    if (txtDiscount.Text.Trim().Length >0)                  //折扣
                    {
                        entityGoods.Discount = double.Parse(txtDiscount.Text.Trim())/10;
                    }
                    entityGoods.MEMO = txtMEMO.Text.Trim();                       /*备注*/
                    if (txtUNITS.Text.Trim().Length > 0)                    /*数量*/
                    {
                        entityGoods.UNITS = int.Parse(txtUNITS.Text.Trim());      
                    }
                    if (txtBUYING_PRICE.Text.Trim().Length > 0)             /*进价*/
                    {
                        entityGoods.BuyPrice = decimal.Parse(txtBUYING_PRICE.Text.Trim());
                    }
                    if (cmbSTOREROOM_ID.SelectedIndex != -1)                 /*仓库编号*/
                    {
                        entityGoods.StoreRoom_ID = cmbSTOREROOM_ID.SelectedValue.ToString().Trim();
                    }
                    ReturnValue resoult = bll_M007_GOODS.AddOrUpdateGoods(entityGoods);

                    if (resoult.IsSuccess)
                    {
                        txtGOODS_ID.Text = resoult.ErrorID;
                        txtGOODS_ID.Tag = txtGOODS_ID.Text.Trim();
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        Method.MessageShow(resoult.ErrorID, dataName);
                        txtGOODS_NM1.Focus();
                        txtGOODS_NM1.SelectAll();
                    }
                    break;
                #endregion
                       
                #region btnExit
                case "btnExit":
                    this.Close();
                    break;
                #endregion

                #region btnClear
                case "btnClear":
                    {
                        ClearControl();
                    }
                    break;
                #endregion

                #region 条码管理
                case "btnNoManage":
                    {
                        if (txtGOODS_ID.Text.Trim().Length>0)
                        {
                            MODEL.MOD_M007_GOODS mod = new XiaoGang.Soft.XGWMS.MODEL.MOD_M007_GOODS ();
                            mod.GOODS_ID = txtGOODS_ID.Text.Trim ();
                            ReturnValue reValue = bll_M007_GOODS.GetSingleData (mod);
                            if(reValue.ResultDataSet.Tables[0].Rows.Count<1)
                            {
                                Method.MessageShow ("W11053","");//请选择商品或输入有效的商品编号！
                                this.Cursor = Cursors.Default;
                                return;
                            }
                            FrmNoManage frm = new FrmNoManage (txtGOODS_ID.Text.Trim ());
                            frm.ShowDialog ();
                        }  
                    }
                    break;
                #endregion

            }
            this.Cursor = Cursors.Default;
            SearchFlag = false;
        }

        protected override void AllTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }

        private void AllTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            string strControlName = ((TextBox)sender).Name;
            switch (strControlName)
            {
                case "txtGOODS_ID":
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
                case "txtGOODS_NO":
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
                case "txtMAX_WARN":               
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
                case "txtMIN_WARN":
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
                case "txtMoney":
                    FormBase.UKeyPress(e, InputType.Dbl);
                    break;
                case "txtDiscount":
                    FormBase.UKeyPress(e, InputType.Dbl);
                    break;
                case "txtUNITS":
                    FormBase.UKeyPress(e, InputType.Num);
                    break;
                case "txtBUYING_PRICE":
                    FormBase.UKeyPress(e, InputType.Dbl);
                    break;
            }
        }

        private void AllTextBox_GotFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtGOODS_ID":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    break;
                case "txtGOODS_NM1":                   
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;
                case "txtGOODS_NM2":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;
                case "txtGOODS_NO":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    break;
                case "txtMAX_WARN":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    ((TextBox)sender).Text = strValue.Replace(",", "");
                    break;
                case "txtMEMO":                    
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;
                case "txtMIN_WARN":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    ((TextBox)sender).Text = strValue.Replace(",", "");
                    break;
                case "txtMoney":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    ((TextBox)sender).Text = strValue.Replace(",", "");
                    break;
                case "txtPROVIDER":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;
            }
        }

        private void AllTextBox_LostFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim().Replace("/", "");
            strValue = strValue.Replace(",", "");
            if (0 == strValue.Length)
            {
                return;
            }

            switch (((TextBox)sender).Name)
            {
                case "txtMAX_WARN":
                    ((TextBox)sender).Text = NumPriceFormat(strValue);
                    break;
                case "txtMIN_WARN":
                    ((TextBox)sender).Text = NumPriceFormat(strValue);
                    break;
                case "txtMoney":
                    ((TextBox)sender).Text = NumPriceFormat(strValue);
                    break;
            }
        }

        private void M007_GOODS_Activated(object sender, EventArgs e)
        {
            if (!blFormLoad)
            {
                string strValueGoodsGroup = cmbGOODS_GROUP.SelectedValue.ToString();
                Method.CmbDataBound("GOODS_GROUP_ID", cmbGOODS_GROUP);
                foreach (System.Data.DataRowView drGoods in this.cmbGOODS_GROUP.Items)
                {
                    if (strValueGoodsGroup == drGoods["GOODS_GROUP_ID"].ToString().Trim())
                    {
                        cmbGOODS_GROUP.SelectedValue = strValueGoodsGroup;
                        return;
                    }
                }
                cmbGOODS_GROUP.SelectedIndex = 0;
            }
            blFormLoad = false;
        }

        private void btnGOODS_GROUP_Click(object sender, EventArgs e)
        {
            M006GoodsGroupEdit form = new M006GoodsGroupEdit();
            if (form.ShowDialog() == DialogResult.OK)
            {
                InitComBox();
            }
        }        

        public  void M007_GOODS_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.ToString().Trim() == "")
            {
                txtGOODS_NO.Text = "";
                txtGOODS_NO.Focus();
            }
        }

        #endregion

    }
}